from marshmallow import Schema, fields, validate
from datetime import datetime

class AppointmentSchema(Schema):
    """预约模式"""
    appointmentId = fields.Str()
    patientId = fields.Str(required=True)
    scheduleId = fields.Str(required=True)
    doctorId = fields.Str(required=True)
    departmentId = fields.Str(required=True)
    appointmentDate = fields.Date(required=True)
    timeSlot = fields.Str(required=True)
    period = fields.Str(validate=validate.OneOf(['上午', '下午', '晚上']), required=True)
    visitType = fields.Str(validate=validate.OneOf(['初诊', '复诊']), dump_default='初诊')
    registrationType = fields.Str(validate=validate.OneOf(['普通门诊', '专家门诊', '特需门诊']), dump_default='普通门诊')
    registrationFee = fields.Float(dump_default=0.0)
    status = fields.Str(validate=validate.OneOf(['预约中', '已到诊', '已取消', '未到诊']), dump_default='预约中')
    remarks = fields.Str()
    paymentStatus = fields.Str(validate=validate.OneOf(['未支付', '已支付', '已退款']), dump_default='未支付')
    createdAt = fields.DateTime(dump_default=datetime.utcnow)
    updatedAt = fields.DateTime(dump_default=datetime.utcnow)

class AppointmentUpdateSchema(Schema):
    """预约更新模式"""
    status = fields.Str(validate=validate.OneOf(['预约中', '已到诊', '已取消', '未到诊']))
    remarks = fields.Str()
    paymentStatus = fields.Str(validate=validate.OneOf(['未支付', '已支付', '已退款']))

class AppointmentQuerySchema(Schema):
    """预约查询模式"""
    patientId = fields.Str()
    doctorId = fields.Str()
    departmentId = fields.Str()
    startDate = fields.Date()
    endDate = fields.Date()
    status = fields.Str(validate=validate.OneOf(['预约中', '已到诊', '已取消', '未到诊', 'all']))
    paymentStatus = fields.Str(validate=validate.OneOf(['未支付', '已支付', '已退款', 'all'])) 